package com.library.controller;



import com.library.domain.BookFull;
import com.library.mapper.BookMapper;
import com.library.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/lib/book")
public class BookController  {
    @Autowired
    BookService bookService;

    @Autowired
    BookMapper bookMapper;
    private String prefix = "system/library/book";

    @GetMapping()
    public String pub(){
        return prefix+"/book";
    }
    @GetMapping("/selectAll")
    public List<BookFull> selectAll() {

        return bookService.selectAll();
    }
    @GetMapping("/selectByIsbn/{isbn}")
    public List<BookFull> selectByIsbn(@PathVariable String isbn) {

        return bookService.selectByIsbn(isbn);
    }
    @GetMapping("/key/{key}")
    public List<BookFull> selectKey(@PathVariable String key){
        return bookMapper.selectKey(key);
    }
    @GetMapping("/selectByName/{bookName}")
    public List<BookFull> selectByName(@PathVariable String bookName)
    {
        return bookService.selectByName(bookName);
    }

    @GetMapping("/selectByAuthor/{authorName}")
    public List<BookFull> selectByAuthor(@PathVariable String authorName) {
        return bookService.selectByAuthor(authorName);
    }
    @GetMapping("/selectByPublisher/{pubName}")
    public List<BookFull> selectByPublisher(@PathVariable String pubName) {
        return bookService.selectByPublisher(pubName);
    }

    @DeleteMapping("/del/{isbn}")
    public Integer delByIsbn(@PathVariable String isbn) {

        return bookService.delByIsbn(isbn);
    }

    @PostMapping("/add")
    public Integer add(@RequestBody BookFull bookFull) {

        return bookService.add(bookFull);

    }

    @PostMapping("/change")
    public Integer change(@RequestBody BookFull bookFull) {

        return bookService.change(bookFull);
    }
}
